package com.yricky.memoria.utils

import java.io.File
import java.nio.charset.Charset

/**
 * UncaughtException处理类,当程序发生Uncaught异常的时候,有该类
 * 来接管程序,并记录 发送错误报告.
 */
class ExceptionHandlerProxy(private val mOrigExceptionHandler: Thread.UncaughtExceptionHandler?) :
    Thread.UncaughtExceptionHandler {
    /**
     * 当UncaughtException发生时会转入该函数来处理
     */
    override fun uncaughtException(thread: Thread, ex: Throwable) {
        File(globalContext.externalCacheDir,"CrashReport_${System.currentTimeMillis()}_${thread.name}.crash")
            .writeText(ex.stackTraceToString(), Charset.defaultCharset())
    }
}